package com.zijie;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Arrays;

public class Test1 {
	public static void main(String[] args)  throws Exception{
		File f1 = new File("E:\\PR\\a.txt");
		InputStream in = new FileInputStream(f1);
		//不断读取文件内容，以及下一个
		int temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp+"\n");
		
		//循环
		in = new FileInputStream(f1);
		int b = 0;
		while((b=in.read()) != -1) {
			System.out.println(b);
		}
		System.out.println("\n");
		
		in = new FileInputStream(f1);
		byte[]  bs = new byte[1024];
		
		int len =  in.read(bs);//从字节输入流中读取到bs.length到数组中
		System.out.println("bs:"+Arrays.toString(bs)+"\n");
		System.out.println("len:"+len+"\n");
		//in.read(bs,0,bs.length);//  = in.read(bs)
		
		in = new FileInputStream(f1);
		bs = new byte[6];//一次性读取1k -> 6
		len = 0 ;
		while((len = in.read(bs))> -1) {;
		System.out.println("bs:"+Arrays.toString(bs)+"有效:"+len+"\n");
		
		}
		
	}
}
